package com.qf.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Component
public class ZkClient {


    @Bean
    public CuratorFramework getClient() {

        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);

        CuratorFramework curatorFramework = CuratorFrameworkFactory
                .builder()
                .connectString("192.168.200.158:2181")
                //连接超时时间
                .connectionTimeoutMs(600000)
                //zookeeper会话超时时间
                .sessionTimeoutMs(600000)
                .retryPolicy(retryPolicy)
                .build();

        curatorFramework.start();
        return curatorFramework;
    }
}
